




#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "legendwindow.h"
#endif

#include <wx/wxprec.h>

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include "wx/legendwindow.h"

IMPLEMENT_DYNAMIC_CLASS(wxLegendWindow, wxWindow)

BEGIN_EVENT_TABLE(wxLegendWindow, wxWindow)
  EVT_PAINT(        wxLegendWindow::OnPaint)
  EVT_LEFT_DOWN(    wxLegendWindow::OnMouse)
  EVT_LEFT_DCLICK(  wxLegendWindow::OnMouse)
  EVT_MOTION(       wxLegendWindow::OnMouseMove)
END_EVENT_TABLE()

wxLegendWindow::wxLegendWindow(
	 wxWindow *parent
):  wxWindow(parent, -1, wxDefaultPosition,
			 wxSize(LEGEND_WIDTH, LEGEND_HEIGHT)),
	m_WinParent(parent) {
	SetBackgroundColour( *wxWHITE );
}



void wxLegendWindow::Add(
	const wxString &lbl,
	const ChartColor &col
) {
	m_Legend.Add( lbl, col );
}


void wxLegendWindow::Clear() {
	m_Legend.Clear();
}


int wxLegendWindow::GetCount() const {
	return ( m_Legend.GetCount() );
}


ChartColor wxLegendWindow::GetColor(
	int n
) const {
	return ( m_Legend.GetColor(n) );
}


wxString wxLegendWindow::GetLabel(
	int n
) const {
	return ( m_Legend.GetLabel(n) );
}



void wxLegendWindow::Draw(
	CHART_HPAINT hp,
	int x,
	int y
) {



	CHART_RECT r;
	r.x = x; r.y = y;
	r.xscroll = 0; r.yscroll = 0;
	GetClientSize( &r.w, &r.h );




	m_Legend.Draw( hp, &r );
}


void wxLegendWindow::OnPaint(
	wxPaintEvent &WXUNUSED(event)
) {
	wxPaintDC dc( this );




	Draw( &dc );
}


void wxLegendWindow::OnMouse(
	wxMouseEvent &event
) {
	wxPoint p = event.GetPosition();

	if ( m_Legend.IsInArrowDown(p.x, p.y) )
	{
		m_Legend.DecPage();
		Refresh();
	}
	else if ( m_Legend.IsInArrowUp(p.x, p.y) )
	{
		m_Legend.IncPage();
		Refresh();
	}
}


void wxLegendWindow::OnMouseMove(
    wxMouseEvent &event
) {
    wxPoint p = event.GetPosition();

    wxClientDC dc(this);

    if ( m_Legend.IsInArrowDown(p.x, p.y) )
    {
        m_Legend.DrawArrow(&dc, ARROW_DOWN, true);
    }
    else if ( m_Legend.IsInArrowUp(p.x, p.y) )
    {
        m_Legend.DrawArrow(&dc, ARROW_UP, true);
    }
    else
    {
        m_Legend.DrawArrow(&dc, ARROW_DOWN, false);
        m_Legend.DrawArrow(&dc, ARROW_UP, false);
    }
}
